﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Transactions.*;
    import Classes.*;

    public class TInstantReady extends Transaction {

        public static var ALL_CROPS:int = -1;
        public static var ALL_SHIPS:int = -2;
        public static var ALL_RESIDENCES:int = -3;

        private var m_harvestable:HarvestableResource;
        private var m_harvestType:String;

        public function TInstantReady(_arg1:HarvestableResource, _arg2:String=null){
            this.m_harvestable = _arg1;
            this.m_harvestType = _arg2;
        }
        override public function perform():void{
            var _local1:Number = 0;
            if (this.m_harvestable){
                _local1 = this.m_harvestable.getId();
            };
            signedCall("UserService.makeInstantlyHarvestable", _local1, this.m_harvestType);
        }
        override protected function onComplete(_arg1:Object):void{
            var _local2:int;
            if (_arg1 != null){
                _local2 = 0;
                if (this.m_harvestType){
                    this.instantReadyAllOfType(this.m_harvestType);
                } else {
                    this.m_harvestable.setFullGrown();
                };
            };
        }
        private function instantReadyAllOfType(_arg1:String):void{
            var _local4:HarvestableResource;
            var _local2:Array = Global.world.getObjectsByTypes([this.getWorldObjectType(this.m_harvestType)]);
            var _local3:Number = 0;
            while (_local3 < _local2.length) {
                _local4 = HarvestableResource(_local2[_local3]);
                if (_local4.getState() == HarvestableResource.STATE_PLANTED){
                    _local4.setFullGrown();
                };
                _local3++;
            };
        }
        private function getWorldObjectType(_arg1:String):int{
            switch (_arg1){
                case "plot":
                    return (WorldObjectTypes.PLOT);
                case "ship":
                    return (WorldObjectTypes.SHIP);
                case "residence":
                    return (WorldObjectTypes.RESIDENCE);
            };
            return (Number.NaN);
        }

    }
}//package Transactions 
